import keras

import myNet01

train_dataset = keras.api.preprocessing.image_dataset_from_directory('dataset/train', image_size=(224, 224),
                                                                     batch_size=32)
val_dataset = keras.api.preprocessing.image_dataset_from_directory('dataset/val', image_size=(224, 224), batch_size=32)

vgg_model = myNet01.create_vgg_model(num_classes=1000)
vgg_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
vgg_model.summary()

history = vgg_model.fit(train_dataset, val_dataset=val_dataset, epochs=10)
loss, accuracy = vgg_model.evaluate(val_dataset)
print(f'Validation accuracy:{accuracy * 100:.2f}%')

import matplotlib.pyplot as plt

plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.plot(history.history['accuracy'], label='Train Accuracy')
plt.plot(history.history['val_accuracy'], label='Val Accuracy')
plt.title('Accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.legend()

plt.subplot(1, 2, 2)
plt.plot(history.history['loss'], label='Train Loss')
plt.plot(history.history['val_loss'], label='Val Loss')
plt.title('Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.legend()

plt.show()
